package com.yourbatis.syntax;

public class LogicalExpression implements Expression {
    private final Expression left;
    private final String op;
    private final Expression right;

    public LogicalExpression(Expression left, String op, Expression right) {
        this.left = left;
        this.op = op;
        this.right = right;
    }

    @Override
    public Object eval() {
        boolean leftVal = (Boolean)left.eval();
        if (op.equals("&&") && !leftVal) return false;
        if (op.equals("||") && leftVal) return true;
        return (Boolean)right.eval();
    }
}
